/**
 * 香草期权组件
 */
import React, { PureComponent } from 'react';
import _ from 'lodash';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { SelectC } from '../../../../comps';
import { connect } from 'dva';
import { config1, dict } from '../config';
@Form.create()
@connect(({ shareOptionManageM, bookM, globalM }) => ({ shareOptionManageM, bookM, globalM }))
export default class BookVanilla extends PureComponent {
  state = {};
  componentDidMount() {
    this.props.onRef(this);
  }
  // 获取表单数据
  getSettingInfo = () => {
    const {
      form: { getFieldsValue, validateFieldsAndScroll },
    } = this.props;
    let formData = getFieldsValue();
    let result = undefined;
    validateFieldsAndScroll((error, values) => {
      if (error) {
        return false;
      } else {
        result = values;
      }
    });
    return result;
  };
  // 表单重置
  resetForm = () => {
    this.props.form.resetFields();
  };
  render() {
    const { Dis2 } = this.state;
    const {
      form: { getFieldDecorator },
      bookVanilla,
      structure,
      bookM: { onlyView },
      globalM: { dataDictionary: dictionary },
    } = this.props;
    const { info } = config1[1]; // 配置文件中 普通香草期权的标题配置
    // 整个组件是否可填写
    const disabledImportant = onlyView || (structure == '1' ? false : true);

    // 普通的select
    const generateSelect = ({ key, data, isRequired }) => {
      let dictArr = [];
      if (dict[key] && dictionary[dict[key]]) {
        dictArr = dictionary[dict[key]].map((item) => {
          return { title: item.value, value: item.code };
        });
      }
      let arr = data || dictArr || [];
      return (
        <div style={{ width: '100%', height: '39px', marginBottom: info[key].space }}>
          <SelectC
            dataIndex={key}
            placeholder=''
            form={this.props.form}
            dataSource={arr}
            disabled={disabledImportant || info[key].isGrey}
            initialValue={bookVanilla[key]}
            rules={[{ required: isRequired ? true : info[key].isRequired, message: '此为必填项' }]}
            positionBody={true}
          />
        </div>
      );
    };
    return <div>{generateSelect({ key: 'exerciseType', isRequired: !disabledImportant })}</div>;
  }
}
